import { FieldType } from "../celltypes";
import CellType from "../celltypes";

export default {
    canUndo: true,
    execute: (context, options, isUndo) => {
        const { sheet, range } = options;
        const ReportFieldCellType = CellType('ReportFieldCellType');
        sheet.suspendPaint();
        if (isUndo) {
            range.cellType(options._oldCellType);
        } else {
            options._oldCellType = range.cellType();
            const cellType = new ReportFieldCellType();
            cellType.fieldType = FieldType.DataSourceField;
            cellType.leftParentType = options.leftParentType;
            cellType.upParentType = options.upParentType;
            cellType.customLeftParentCell = options.customLeftParentCell;
            cellType.customUpParentCell = options.customUpParentCell;
            cellType.showType = options.showType;
            cellType.expandType = options.expandType;
            cellType.row = range.row;
            cellType.col = range.col;
            cellType.rowCount = range.rowCount;
            cellType.colCount = range.colCount;
            range.cellType(cellType);
        }
        sheet.resumePaint();
    }
}